package com.banyuan.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author 陶继发
 * @version 1.8
 */
//动态代理
@SuppressWarnings("all")
public class Main {
    public static void main(String[] args) {
        TrainTicket trainTicket = new TrainTicket();

        Ticket ticket =(Ticket) Proxy.newProxyInstance(
                trainTicket.getClass().getClassLoader(),
                trainTicket.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("有序排队11111!");
                        Object invoke = method.invoke(trainTicket, args);
                        System.out.println("加20块钱!");
                        System.out.println();
                        return invoke;
                    }
                }
        );

        ticket.sellTicket();
        ticket.sellPlaneTicket();
        ticket.sellTrainTicket();
    }
}
